
public class p1012_1_407ms {

	public static//
	// -----
	// -----
	class Main {
		public static void main(String[] args) throws Exception {
			java.io.BufferedReader reader = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
			while (true) {
				int k = Integer.parseInt(reader.readLine());
				if (k == 0)
					return;
				System.out.println(process(k));
			}
		}

		static int[] cache = new int[14];

		static int process(int k) {
			if (cache[k] > 0)
				return cache[k];
			int m = k + 1;
			while (!possible(k, m))
				m++;
			return cache[k] = m;
		}

		static boolean possible(int k, int m) {
			int p = 0, left = 2 * k;
			do {
				p = (p + m - 1) % left--;
			} while (p >= k);
			return left < k;
		}
	}

	// -----
	// -----

	public static void main(String[] args) throws Exception {
		Judge.run();
	}

}
